# Commerce Shipping - arbitrary calculations

I'm using Drupal Commerce to create a simple shop and I wish to add shipping cost calculations based on the weight (in grams) of items in the cart. I have set a weight field on each product so I can work out what the total is, but the client has specified arbitrary prices depending on weight and destination:

``````UK
weight = 0 price = 0.00
weight < 250 price = 1.00
weight < 500 price = 1.50
weight < 750 price = 2.00
weight < 1000 price = 3.00
weight < 2000 price = 5.00

Europe
weight = 0 price = 0.00
weight < 250 price = 2.50
weight < 500 price = 4.00
weight < 750 price = 5.00
weight < 1000 price = 6.25
weight < 1250 price = 7.50
weight < 1500 price = 8.75
weight < 1750 price = 10.00
weight < 2000 price = 11.25

Other
weight = 0 price = 0.00
weight < 250 price = 4.00
weight < 500 price = 6.50
weight < 750 price = 8.75
weight < 1000 price = 11.25
weight < 1250 price = 13.75
weight < 1500 price = 16.25
weight < 1750 price = 18.75
weight < 2000 price = 21.25
``````

Would I need to add a shipping calculation rule for each possible scenario or is there a way to configure rules to look up a table?

## 2 Answers

I found a module that does exactly what I want: Commerce Shipping Weight Tariff. I set up three services, one for each destination, and used rules based on the shipping address to work out which service to use. Then I added the weight tariffs for each service.

It wouldn't be a bad idea to create a lookup table with a single Rules action that knows how to read the data from the table and set the shipping rate accordingly. However, if you aren't a developer, you can configure this entirely through Rules.

Shipping rates are passed through Rules similarly to product prices, so you can work with 1 or multiple flat rates (from https://drupal.org/project/commerce_flat_rate) and use multiple rate calculation rules per flat rate to adjust the price based on the destination and the total order weight. I can't recall if we got Rules integration for total order weight into Commerce Physical Products or not, so you might start by looking there.