Kris01's avatar

I need assistance with this problem

Hi guys. I have a problem. I am working on an e-commerce application and I need to calculate the shipping cost of the customer order. The shipping cost depends on the items ordered, on their width, length, height and weight. I have 5 different available packages, and I need to calculate the items ordered in which package need to go. Let's make an example. I have a package that is 100 Γ— 60 Γ— 60 cm and maximum weight up to 10kg. I need to take the items that the client is ordering and see if they fit in this package. How can I build an algorithm that does that?

0 likes
7 replies
martinbean's avatar

@kris01 By writing some code?

You need to calculate the volume of the items ordered, and then work out how many packages you need to pack those items.

Kris01's avatar

@martinbean for example. Let's say a guy orders a phone and headphones. Let's say the phone packages is 20 x 15 x 10 volume = 3000cm3 Let's say the headphone package is 30 x 20 x 15 voulume = 15000cm3

The package volume is 100 * 60 * 60 = 360000cm3 products volume = 3000cm3 + 15000cm3 = 18000cm3

360000cm3 - 18000cm3 = 18000cm3

so the products would fit.

would this be accurate?

tykus's avatar

@Kris01 it is not necessarily so easy - you could could not fit two items in that box if one item is 60 * 60 * 60 and another item 100 * 10 * 10 - even though the volume test says they will fit!

1 like
Kris01's avatar

@tykus You're right, how would you solve this problem? Do you have any idea?

Kris01's avatar

@tykus I should for first thing see if the widht, length and height fit and then calculate the voulme?

Please or to participate in this conversation.