Custom filters

Filters are used to construct promotions as discussed in promotion anatomy. The XML model of a filter becomes part of the promotion XML Model. Once you implement a custom filter, use it to compose your custom promotions. Custom filters must implement the com.ibm.commerce.marketing.promotion.condition.Filter interface. Its definition is given below:

package com.ibm.commerce.marketing.promotion.condition;

import com.ibm.commerce.marketing.promotion.runtime.LineItemSet;
import com.ibm.commerce.marketing.promotion.runtime.PromotionContext;
import com.ibm.commerce.marketing.promotion.xml.XMLizable;

/**
 * Contains the IBM Copyright information for WebSphere Commerce.
 * @author changl
 */

public interface Filter extends XMLizable {
   /**
    * IBM copyright notice field.
    */
    public static final String COPYRIGHT = 
          com.ibm.commerce.copyright.IBMCopyright.SHORT_COPYRIGHT;
    
    /**
     * This method filters the <code>LineItemSet</code>.
     * @param input <code>LineItemSet</code>
     * @param context <code>PromotionContext</code>
     * @return <code>LineItemSet</code>
     */

    LineItemSet filter(LineItemSet input, PromotionContext context);
}

The logic in your filter is encapsulated in the filter method declared in the Filter interface. This method is the worker method. It takes a LineItemSet as input, and returns a LineItemSet that is a subset of the input LineItemSet. The PromotionContext is passed to this method, and it provides the filter method a context in which to operate.

This interface is a subclass of XMLizable. As a result, develop an XML model for your new Filter. A list of sample XML models for the existing filter types are provided in sample Filter XML Fragments. The following sample illustrates one:

<Filter impl="com.ibm.commerce.marketing.promotion.condition.CategoryFilter>
    <IncludeCategory>
       <CategoryKey>
          <DN>o=root organization</DN>
          <Name>Store 201 Pants</Name>
       </CategoryKey>
    </IncludeCategory>
    <ExcludeCategory>
       <CategoryKey>
          <DN>o=root organization</DN>
          <Name>Store 201 Sweaters</Name>
       </CategoryKey>
    </ExcludeCategory>
</Filter>

You must replace the value in the impl attribute of the Filter element with the fully qualified class name of your custom filter. The content model of your Filter element is completely open-ended.

All custom filter implementations must be thread safe and re-entrant. Related reference