KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > store > shipping > BaseShippingMethod


1 /*
2  * Created on May 26, 2004
3  */

4 package com.openedit.store.shipping;
5
6 import java.util.HashMap JavaDoc;
7 import java.util.Iterator JavaDoc;
8 import java.util.Map JavaDoc;
9
10 import org.openedit.money.Money;
11
12 import com.openedit.store.Cart;
13 import com.openedit.store.CartItem;
14 import com.openedit.store.HandlingCharge;
15 import com.openedit.store.ShippingMethod;
16
17 /**
18  * @author cburkey
19  *
20  */

21 public abstract class BaseShippingMethod implements ShippingMethod
22 {
23     protected String JavaDoc fieldId = "";
24     protected String JavaDoc fieldDescription = "";
25     protected Map JavaDoc fieldHandlingCharges;
26
27     protected Money fieldCost = Money.ZERO;
28     protected double fieldPercentageCost = 0.0;
29
30     // thresholds that indicate when this shipping method can be used
31
protected Money fieldLowerThreshold = Money.ZERO;
32     protected Money fieldUpperThreshold = null;
33     
34     protected boolean fieldHidden;
35     
36     public Money getCost()
37     {
38         return fieldCost;
39     }
40     
41     public void setCost(Money inCost) {
42         fieldCost = inCost;
43     }
44     public Money getLowerThreshold()
45     {
46         return fieldLowerThreshold;
47     }
48     public void setLowerThreshold(Money inLowerThreshold)
49     {
50         fieldLowerThreshold = inLowerThreshold;
51     }
52     public Money getUpperThreshold()
53     {
54         return fieldUpperThreshold;
55     }
56     public void setUpperThreshold(Money inUpperThreshold)
57     {
58         fieldUpperThreshold = inUpperThreshold;
59     }
60
61     public double getPercentageCost()
62     {
63         return fieldPercentageCost;
64     }
65
66     public void setPercentageCost(double inPercentageCost)
67     {
68         fieldPercentageCost = inPercentageCost;
69     }
70
71     
72     
73     public String JavaDoc getDescription() {
74         return fieldDescription;
75     }
76     public void setDescription(String JavaDoc inDescription) {
77         fieldDescription = inDescription;
78     }
79     public String JavaDoc getId() {
80         return fieldId;
81     }
82     public void setId(String JavaDoc inId) {
83         fieldId = inId;
84     }
85     public Map JavaDoc getHandlingCharges()
86     {
87         if ( fieldHandlingCharges == null )
88         {
89             fieldHandlingCharges = new HashMap JavaDoc();
90         }
91         return fieldHandlingCharges;
92     }
93
94     public void setHandlingCharges(Map JavaDoc inHandlingCharges)
95     {
96         fieldHandlingCharges = inHandlingCharges;
97     }
98
99     public HandlingCharge getHandlingCharge(String JavaDoc inLevel)
100     {
101         return (HandlingCharge)getHandlingCharges().get(inLevel);
102     }
103
104     public void addHandlingCharge(HandlingCharge inHandlingCharge)
105     {
106         getHandlingCharges().put(inHandlingCharge.getLevel(), inHandlingCharge);
107     }
108     public Money getHandlingCharge(Cart inCart)
109     {
110         Money totalPrice = Money.ZERO;
111         if( !inCart.isEmpty() )
112         {
113             // add in any per-item handling charges
114
for ( Iterator JavaDoc it = inCart.getItemIterator(); it.hasNext(); )
115             {
116                 CartItem item = (CartItem)it.next();
117                 String JavaDoc handlingChargeLevel = item.getProduct().getHandlingChargeLevel();
118                 if ( handlingChargeLevel != null )
119                 {
120                     HandlingCharge handlingCharge = getHandlingCharge( handlingChargeLevel );
121                     if ( handlingCharge != null )
122                     {
123                         Money handlingCost = handlingCharge.getCost();
124                         handlingCost = handlingCost.multiply( item.getQuantity() );
125                         totalPrice = totalPrice.add( handlingCost );
126                     }
127                 }
128             }
129         }
130         return totalPrice;
131     }
132
133     public boolean isHidden()
134     {
135         return fieldHidden;
136     }
137
138     public void setHidden(boolean inHidden)
139     {
140         fieldHidden = inHidden;
141     }
142
143 }
144
Popular Tags