1 package org.paneris.jammyjoes.model; 2 3 import java.util.Enumeration; 4 5 import org.paneris.jammyjoes.model.generated.DeliveryZoneBase; 6 import org.paneris.jammyjoes.util.JammyJoesUtil; 7 8 public class DeliveryZone extends DeliveryZoneBase { 9 public DeliveryZone() { 10 } 11 12 public String quote(String in) { 13 return getDatabase().getDbms().getQuotedName(in); 14 } 15 16 public DeliveryCharge getMaxCharge() { 17 Enumeration e = 18 getJammyjoesDatabaseTables().getDeliveryChargeTable().selection( 19 quote("zone") + " = " + this.getTroid(), 20 quote("weight") + " desc", 21 true); 22 if (e.hasMoreElements()) 23 return (DeliveryCharge) e.nextElement(); 24 return null; 25 } 26 27 public DeliveryCharge getCharge(double weight) { 28 Enumeration e = 29 getJammyjoesDatabaseTables().getDeliveryChargeTable().selection( 30 quote("zone") + " = " + this.getTroid() + " AND " + quote("weight") + " > " + weight, 31 quote("weight") + " asc", 32 true); 33 if (e.hasMoreElements()) 34 return (DeliveryCharge) e.nextElement(); 35 return null; 36 } 37 38 public DeliveryCharge getChargeValue(double v) { 39 double value = JammyJoesUtil.roundTo2dp(v); 40 Enumeration e = 41 getJammyjoesDatabaseTables().getDeliveryChargeTable().selection( 42 quote("zone") + " = " + this.getTroid() + " AND " + quote("weight") + " < " + value, 43 quote("weight") + " desc", 44 true); 45 if (e.hasMoreElements()) 46 return (DeliveryCharge) e.nextElement(); 47 return null; 48 } 49 }