2

I am building out a UPS integration into my app which will allow users to set & save shipping boxes they have in their stock including the box's length, width, and height in inches. Each product that the user sells will now also have its own length, width, and height.

When a customer goes to order, I need to take all of the products in the cart along with their dimensions, and figure out the most efficient (smallest possible) box size to use in the list of available boxes.

I found this link: https://www.pluginhive.com/knowledge-base/box-packing-calculation-shipping-rates-based-weights-dimensions-2 and tried to follow the logic, but it seems flawed. It says to loop through the products and find the one with the largest length and do the same for the one with the largest width and then add up the height of all products together to get the final dimensions.

Example (LxWxH) Product 1 is (5x4x2) Product 2 ix (3x7x3) Product 3 is (4x6x4)

The final dimensions would be 5x7x9. I would then find the smallest box from the available boxes that is at least as big as all 3 dimensions. But this bothers me as the user can stack their product in different ways. They can turn the product sideways and stack them side by side in which cause adding up the total of all heights wouldn't make sense. Would I just repeat the above method for all 3 possibilities? I.E. first get the max length & max width & total height and try to find the best box, then get the max length & max height & total width and try to find the best box, and then get the max height & max width & total length and try to fine the best box?

Mike
  • 430
  • 3
  • 7
  • 16
  • This is an arduous problem, it is known to be NP-hard. I don't think that there is a much better way than trying all ways to pack the items with all possible orientations (the number of possibilities can be astronomical), and see which box would fit. Now telling which box choice is "optimal" is not defined. Also think that you will have to output packing instructions, as tight packings may be difficult to guess. –  Jul 28 '21 at 07:36

1 Answers1

0

Alternatively, print as a multi-piece shipment. one box per product but may save shipping costs on international shipping