Demand-driven optimization of resources flows across the whole supply chain