作業 3:定義 pricing 規則作業
定義一項作業來計算合格客戶的租金,並且使用 RetePlus 演算法來執行規則。
關於這項作業
程序
- 在規則流程圖中選取 pricing 規則作業。
- 在「內容」視圖中,按一下規則選擇,然後按一下編輯。
- 在「選取規則」對話框中,選取 pricing 規則套件。使用箭頭將它移至旁邊的畫面,然後按一下確定。
現在,該規則作業含有 pricing 規則套件中的所有規則。
- 在「內容」視圖中,按一下規則作業,針對演算法,選取 RetePlus。 RetePlus 模式比較適合定價規則,因為它們使用推斷。這表示工作記憶體中的物件由規則所修改,並且應重新評估用於發動規則的條件。如需 RetePlus 模式的相關資訊,請參閱引擎的執行模式。
- 在「內容」視圖中,按一下選取規則,在選擇執行時期規則選項之下,選取靜態 BAL。
- 輸入下列程式碼:
the pickup date of 'the current rental agreement' is after or the same as the effective date of 'the rule', or by default the start date of the session and the pickup date of 'the current rental agreement' is before the expiration date of 'the rule', or by default the end date of the session透過這項執行時期規則選擇陳述式,您指定只有依舊有效且在取車日期之前尚未到期的 pricing 規則,才能在執行時期評估為 pricing 規則作業的一部分。
- 在「內容」視圖中,按一下最終動作,選取 IRL,然後輸入下列程式碼:
java.util.List offersList = new ArrayList(rental.offers); Collections.sort(offersList); Iterator it = offersList.iterator(); while (it.hasNext()) { Offer offer = (Offer) it.next(); session.displayMessage(" * Offer: " + offer); } session.displayMessage(" # Best Offer: " + rental.bestOffer);執行完規則作業之後,「主控台」輸出會顯示訊息,其中列出所有可用的優惠價格,並顯示最適合客戶的優惠價格。
- 由於您使用 IRL 作為最終動作,您必須新增用於 BOM 類別的匯入項目:
- 按一下規則流程圖中的空白處。
- 在規則流程的「內容」視圖中,按一下匯入項目。
- 輸入下列匯入項目:
import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Date; import carrental.Offer; use rental; use session;
- 儲存您的工作。
結果
在下一項作業中,您將定義條件,以便在規則流程的執行路徑中,透過這些條件在 eligibility 規則作業和 pricing 規則作業之間進行轉移。