Blog posts of '2012' 'June'

RSS
Exclude Ground Shipping Based on State- Wednesday, June 13, 2012

First, I recommend checking if a Country/State/Zip has been provided, because the “Estimate Shipping” will work even if they are not selected, and depending on rate calculation method (shipping plugin), you could get funny results, or an error. (Only US and Canada have states.)   For this, we use the ErrorExit record Type.  This will Exit if the Expression (condition) evaluates to true, and the customer will see the message calculated in the Description Expression.  Note, that this is a String Expression, so be sure to include quotes for a literal value.

Order

10

Type

ErrorExit

Name

Missing Country State Zip

Expression

ShippingAddress.Country = null or ShippingAddress.ZipPostalCode = null or ("US,CA".Contains(ShippingAddress.Country.TwoLetterIsoCode) and ShippingAddress.StateProvince = null)

Description Expression

"Please Enter Country, State, and Postal Code"

Then, let’s say we want to prevent shipping if the State is Alaska or Hawaii.  We would use the ErrorExit type here too:

Order

20

Type

ErrorExit

Name

No Shipping to Alaska and Hawaii

Expression

"AK,HI".Contains(ShippingAddress.StateProvince.Abbreviation)

Description Expression

"Sorry, we can’t ship to Alaska or Hawaii"

The condition Expression could have also been written as

Expression

ShippingAddress.StateProvince.Abbreviation = "HI" or ShippingAddress.StateProvince.Abbreviation = "AK"

But when using an “or”, be sure to use parenthesis if you have a more complex expression that includes “and”s too.

Alternately, you may just want to exclude just Ground shipping to Alaska and Hawaii.  For example, you want to use the Shipping.ByWeight rate calculation method, but don’t want to offer Ground to Alaska or Hawaii.  Then the above would instead be entered with an Option type:

Order

20

Type

Option

Name

Ship By Weight but no Ground for AK and HI

Expression

true

Rate Expression

Shipping.ByWeight

Name Expression

"AK,HI".Contains(ShippingAddress.StateProvince.Abbreviation) and [$Name].Contains("Ground") ? "" : [$Name]

For the Option type, the Expression field is a condition.  If it evaluates to true, then the option record is processed, otherwise it's skipped.  The Rate Expression can either be a decimal expression calculating the actual rate you want to charge, or the name of a shipping plugin.  The Name Expression calculates the shipping option Name shown to the customer.  However, if the Name Expression evaluates to blank (""), then Shipping Director will exclude the Option.  The [$Name] is a built-in variable that contains the Name of the shipping option as returned by the other rate caclulation plugin.  So, here we are saying "if the state is Alaska or Hawaii, then exlude the named option, else show the named option".  The If-Then-Else is achieved using the " ? : " ternary operator -  condition ? if-true : if-false.

Tags :  ExcludeOptionErrorExit
Comments (4)
Per Item Shipping Rates- Tuesday, June 12, 2012

Here's a simple but useful shipping scenario:

First Item shipping would be £3.50
Each additional Item adds £1.00

So, for example, 3 items would be £3.50 + £1 + £1 = £5.50

This is easily handled by Shipping Director with a single Option type record:

Type:

Option

Name:

Shipping Rate

Expression:

true

Rate Expression:

3.50 + ((Items.Sum(Quantity)-1) * 1.00)

You can even decide to charge different rates for different countries or postal codes.  For example, shipping to the Highlands and the islands should be

First Item shipping would be £5.50
Each additional Item adds £1.50

For that, we would just add an OptionExit type record ordered before the previous one.  

Type:

OptionExit

Name:

Shipping Rate

Expression:

",AB,BT,DD,HS,IM,IV,KA,PA,PH,TR,ZE,".Contains( ShippingAddress.ZipPostalCode.Substring(0,2) )

Rate Expression:

5.50 + ((Items.Sum(Quantity)-1) * 1.50)

OptionExit will exit with the calculated rate when the "Expression" condition is true.  Whereas "Option" with true expression will return the caclulated rate, and continue looking for more Options.

(Note, the above postal codes are just examples.  Determining all the actual codes for the Highlands & islands is more complex)

And finally, a little about the "Name:" field.  This is the option's name displayed to the customer.  In the examples above both Option records used the same Name "Shipping Rate".  But, the Highlands Option could have used "Shipping to Highlands and Islands".   Or, you can also include a "Name Expression".  If none is present, then the "Name" is displayed to the customer.  The Name Expression allows you to caclulate the option's name displayed to the customer.  For examples, see the other blogs like this one where the weight is included in the option name, and see this blog about using localized resources

Tags :  RatePerItem
Comments (2)