Optimizing the production and packaging of solid pharmaceuticals