Optimizing inventory flow