In OpenLayers, you can generate filters programmatically using the OpenLayers.Filter classes. These can be used in conjunction with the vector layers using the WFS protocol to be serialized with OGC Filter Encoding. We have a filter example demonstrating filter serialization and several examples demonstrating the WFS protocol. If a vector layer has a filter property with a filter like the one in the above filter example, that filter will get serialized with Filter Encoding in GetFeature requests.
OpenLayers doesn't currently have a parser for CQL, but creating one is very much within reach. A CQL parser would allow you to write CQL in your client side code and have that serialized using OGC Filter Encoding in requests to the server.
What iant said is right. If you only ever want to make requests to GeoServer, then CQL will work. If you want to use filters in various contexts (like filtering features client side or serializing filters in WFS queries), then OGC Filter Encoding is the way to go.