An Algorithm for the Optimal Allocation of Products and Resources in Multi-Site Environments