Stock control and cost optimization