Capsules help bacteria attach to surfaces - e.g. Streptococcus mutans attaches to your teeth using a capsule. Capsules also function as a protective layer - as in S. pneumoniae which can avoid phagocytyosis in the blood only if it has a capsule. The main functions of fimbriae are attachment and transport. The site of attachment of the flagellum to the cell wall is more complex, however. This motor is under complex control in bacteria.
Many bacteria exhibit chemotactic behavior in which they can move towards a source of food.