Application management : Tools : Web Services : Developing a Web service client : Searching/filtering for instances of business objects
Searching/filtering for instances of business objects
It is possible to search for particular business objects with certain characteristics. For example, it is possible to look for all persons having a last name of 'Peters', or having the initials 'J.A'.
For this, a filter class is available, for example, PersonFilter. This class has setter methods for each field you can filter on. It is possible to filter on multiple fields at the same time. Searching on multiple fields is always done using ‘in’ and ‘like’ operators. For example, searching for all persons with initials 'J.A' and last name 'Peters' will only match the persons with the same initials and the same last name.
The setter methods in your filter class accept two parameters, the first parameter is the filter-operator to use, and the second parameter is the value to filter on. The following are the supported filter operators:
Filters on exact matching values
"equals": the field value should be exactly equal to the filter value.
"notEquals": the field value should not be equal to the filter value.
"notEqualsOrEmpty": the field value should not be equal to the filter value or should be empty.
Filters that contain a value
"contains": the field value contains the filter value.
"notContains": the field value does not contain the filter value.
"containsAValue": the field value contains any value.
Filters that match the beginning of values
"startsWith": field value should start with the filter value.
"notStartsWith": field value should not start with the filter value.
Filters that match the end of values
"endsWith": the field value should end with the filter value.
"notendsWith": the field value should not end with the filter value.
Filter on values that are strictly greater than a value
"greater": the field value should be greater than the filter value.
Filter on values that are greater than or equal to a value
"greaterEqual": the field value should be greater than, or equal to the filter value.
Filter on values that are strictly less than a value
"less": the field value should be less than the filter field value.
Filter on values that are less than or equal to a value
"lessEqual": the field value should be less than or equal to the filter field value.
Filter on on empty values
notContainsAValue": the field value is null (empty).
* 
Note that the operators are case-sensitive. For convenience, a Java class is defined with constants for these operators. This class is called ‘nl.planon.nyx.common.filter.FilterOperator'. It is preferred to use the constants of this class instead of the strings mentioned above.
However, it is not always possible to use all filter operators on all fields. For example, filtering on date fields starting with '12' will not work. In this case, an exception will be thrown to your Web service client.
Filtering on field names
You can use the actual field names while specifying the filtering criteria.
For example, the ParentRef field on the Property business object in the Web Service definition.
* 
However, for using this field for filtering, you must first add the field to the layout and put the field settings, Inselection=true and Simple selection=true in the FieldDefiner TSI.
The following example explains the settings for the ParentRef field:


PropertyFilter myFilter = new PropertyFilter();
FieldFilter[] fieldFilters = new FieldFilter[1];
fieldFilters[0]= new FieldFilter("","","");
fieldFilters[0].setFieldName("ParentRef");
fieldFilters[0].setFilterValue("301");
fieldFilters[0].setOperator("equals");
myFilter.setFieldFilters(fieldFilters);
Filtering DisplaytypeRef fields:
You can use the DisplayTypeRef fields in the filtering as explained in the following example:
Add the IsArchived field to Inselection=true and ensure that it is added in the layout before you generate the webservices.

FieldFilter[] fieldFilters = new FieldFilter[2];
fieldFilters[0]= new FieldFilter();
fieldFilters[1]= new FieldFilter();
fieldFilters[0].setFieldName("ParentRef");
fieldFilters[0].setFilterValue("301");
fieldFilters[0].setOperator("equals");
fieldFilters[1].setFieldName("IsArchived");
fieldFilters[1].setFilterValue("true");
fieldFilters[1].setOperator("equals");
myFilter.setFieldFilters(fieldFilters);
Java examples for using filters in webservice client:

// find all persons whose last name ends width “eters”:
PersonFilter filter1 = new PersonFilter();
filter1.setFilterLastName(FilterOperator.ENDS_WITH, “eters”);
// find all persons whose working address equals
// to the address with primary key (syscode) 25:
PersonFilter filter2 = new PersonFilter();
filter2.setFilterAddressRef(FilterOperator.EQUALS, 25);
// find all addresses whose free field 7 is less or equal to 141:
// (assuming free field 7 represents an integer field)
AddressFilter filter3 = new AddressFilter();
Filter3.setFilterFreeField7(FilterOperator.LESS_EQUAL, 141);
instance.find(final String aSessionId, Filter3);
Java example for using the 'find method' in webservice client

// find all addresses whose free field 7 is less or equal to 141:
// (assuming free field 7 represents an integer field)
AddressFilter filter1 = new AddressFilter();
Filter1.setFilterFreeField7(FilterOperator.LESS_EQUAL, 141);
instance.find(final String aSessionId, filter1);