This's the right way to using weight jurisdiction gateway to get shipping rate. But when i look at your implement, i don't think the GetRate() used correctly. It should be
GetRate(shippingMethodId, shipment, ref message);
There're some reasons GetRate returns null, i example shipment or shipment.ShippingAddress is null.
Adding shippingAddress to the shipment did the trick, thank you!
Basically I'm wondering how to set up shipping cost based on weight of the ordered items? For example, the base price for shipping is $5 then if the total weight > 1 kg add an extra $5 to the shipping cost. In CM, we have setup a shipping method with the weight/jurisdiction gateway. When calculating the shipping cost we do:
var methods = ShippingManager.GetShippingMethodsByMarket(MarketId.Default.Value, false).ShippingMethod;
var rates = methods.Where(shippingMethodRow =>
currentLanguage.Equals(shippingMethodRow.LanguageId, StringComparison.OrdinalIgnoreCase) &&
String.Equals(currencyId, shippingMethodRow.Currency, StringComparison.OrdinalIgnoreCase)).
OrderBy(shippingMethodRow => shippingMethodRow.Ordering).
Select(shippingMethodRow => GetRate(shipment, shippingMethodRow));
This selects the correct shipping method but GetRate returns null. Any ideas why or is there another(better?) way to do it?
We are using Commerce 9.4.