The latest versions of AE come with FreeForm. This is a perfect plug-in to make a flag wave. You could also use displacement mapping, also included.
I'd start by doing a google search for After Effects Waving Flag Tutorial. You'll find a bunch of options. I'd go with FreeForm.
Zaxwerks have a 3D flag plug-in and as Rick already suggested, the various flavors of Freeform can do flags...