a!match(): quote a delivery price
Hard
A courier's website quotes a delivery price from the destination and the parcel weight in kilograms. Return the quote:
- a weight of 0 or less, whatever the destination —
"Invalid weight" - destination
"HOME"— up to 2 kg"Price: 5", up to 10 kg"Price: 9", heavier"Price: 15" - destination
"EU"— up to 2 kg"Price: 12", heavier"Price: 20" - any other destination —
"Quote on request"
The website sends the destination exactly as the customer typed it, so "home", "Home" and "HOME" all mean the same place.
Watch out: equals compares text exactly, capital letters included, and the first condition that holds wins. A then can hold another a!match().
Inputs
ri!destination— Textri!weight— Decimal
ri! Rule Inputs
ri!destinationText"HOME"
ri!weightDecimal1.5
Example 1 — A light parcel at home
Input: ri!destination
"HOME"
Input: ri!weight
1.5
Output:
"Price: 5"
Example 2 — Home, typed in lower case
Input: ri!destination
"home"
Input: ri!weight
6
Output:
"Price: 9"
Example 3 — A heavy parcel at home
Input: ri!destination
"Home"
Input: ri!weight
12
Output:
"Price: 15"
Example 4 — Exactly 2 kg to the EU
Input: ri!destination
"EU"
Input: ri!weight
2
Output:
"Price: 12"
Example 5 — Heavier, to the EU
Input: ri!destination
"eu"
Input: ri!weight
2.5
Output:
"Price: 20"
Example 6 — Somewhere else
Input: ri!destination
"US"
Input: ri!weight
1
Output:
"Quote on request"
Example 7 — A weight of zero
Input: ri!destination
"HOME"
Input: ri!weight
0
Output:
"Invalid weight"
Example 8 — A bad weight to anywhere else
Input: ri!destination
"US"
Input: ri!weight
-1
Output:
"Invalid weight"
Appian Expression Tips
- • Use
ri!variableNamefor rule inputs - • Use
a!localVariables(local!x: …, body)for locals - • Use
a!forEach(items: …, expression: fv!item)to iterate - • Use
where()/reject(fn!isnull, list)to filter